﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;

namespace Milan
{
	public struct ArgumentDefinition
	{
		public ArgumentDefinition(string _name, string _heading, int _position, bool _required, string _help)
		{
			name = _name;
			heading = _heading;
			position = _position;
			required = _required;
			help = _help;
		}
		string name;
		string heading;
		int position;
		bool required;
		string help;
		static NameValueCollection ParseCommandLine(ArgumentDefinition[] argumentDefinitions, string[] args)
		{
			NameValueCollection returns = new NameValueCollection();
			foreach (var def in argumentDefinitions)
			{
				foreach (var arg in args)
				{
					int position = 0;
					if (def.heading != null && arg.StartsWith(def.heading))
					{
						if (def.position == position)
						{
							returns.Add(def.name, arg);
							break;
						}
						++position;
					}
					else
					{
						if (def.position == position)
						{
							returns.Add(def.name, arg);
							break;
						}
						++position;
					}
				}
			}
			return returns;
		}
	}
}
